package com.weed.pattern.filter2;

import lombok.AllArgsConstructor;

import java.util.List;

/**
 * 组合过滤器链
 *
 * @author zhong.wang
 * @date 2024/10/24
 */
@AllArgsConstructor
public class CompositeFilter<C extends FilterContext> implements Filter<C>  {

    /**
     * 过滤器list
     */
    private final List<Filter<C>> filters;


    /**
     * 执行过滤
     *
     * @param filterContext 过滤内容
     * @return
     */
    @Override
    public Boolean filter(C filterContext) {
        if (null == filters) {
            return Boolean.TRUE;
        }
        for (Filter filter : filters) {
            if(!filter.filter(filterContext)){
                return Boolean.FALSE;
            }
        }
        return Boolean.TRUE;
    }
}
